package com.rc.gongr.daoImpl;

import com.rc.gongr.dao.GongDao;
import com.rc.gongr.pojo.Gong;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * This implementation of the GongDAO actually implements all of the Gong activities, and manipulates a list object,
 * standing in for an implementation of Hibernate, or another ORM framework
 *
 * @author Andrew Bell
 */
public class GongDaoImpl implements GongDao {
    private final List<Gong> postHistory = new ArrayList<Gong>();

    /**
     * Posts gong object to your storage method of choice.
     *
     * @param comment String to be posted for the comment text of the gong
     */
    @Override
    public void postGong(String comment) {
        Date newTimestamp = new Date();
        Gong newGong = new Gong(comment, newTimestamp);
        postHistory.add(newGong);
    }

    /**
     * Returns the string text of the last gong, used for diagnostics/confirmation
     *
     * @return String of the comment + timestamp
     */
    @Override
    public String getLastGong() {
        return toString(postHistory.get(postHistory.size() - 1));
    }

    /**
     * Returns the String of a given gong object
     *
     * @param gong gong object to retrieve String from
     * @return gong comment + timestamp
     */
    private String toString(Gong gong) {
        return (gong.getComment() + " " + gong.getTimestamp());
    }
}
